package it.ilgrv.demiurgo.persistence.tables.inscription;

import it.ilgrv.demiurgo.persistence.tables.faction.Association;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;


/**
 * The persistent class for the availableassociation database table.
 * 
 */
@Entity
@NamedQuery(
		name = "Availableassociation.search.meeting.association",
		query = "SELECT aa\nFROM Availableassociation aa\nWHERE\n\taa.association = :association\nAND aa.meeting = :meeting")
public class Availableassociation extends it.ilgrv.demiurgo.persistence.GenericTable implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	private int version;

	//bi-directional many-to-one association to Association
    @ManyToOne
	private Association association;

	//bi-directional many-to-one association to Meeting
    @ManyToOne
	private Meeting meeting;

	// bi-directional one-to-many association to Partecipant
	@OneToMany(mappedBy = "availableassociation")
	private Set<Partecipant>	partecipants;

    public Availableassociation() {

    }

	/**
	 * return if exist
	 * 
	 * @param em
	 * @param m
	 * @param a
	 * @return
	 */
	public static boolean isExistAvailableassociation(EntityManager em, Meeting m,
			Association a) {
		return isExist(em
								.createNamedQuery("Availableassociation.search.meeting.association",
													Availableassociation.class)
								.setParameter("meeting", m)
								.setParameter("association", a)
								.getResultList());
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getVersion() {
		return this.version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	public Association getAssociation() {
		return this.association;
	}

	public void setAssociation(Association association) {
		this.association = association;
	}
	
	public Meeting getMeeting() {
		return this.meeting;
	}

	public void setMeeting(Meeting meeting) {
		this.meeting = meeting;
	}

	public Set<Partecipant> getPartecipants() {
		return partecipants;
	}

	public void setPartecipants(Set<Partecipant> partecipants) {
		this.partecipants = partecipants;
	}
	
	
}